package com.vitech.javacertification.threads.sharedcell;

public class SharedCell {
	
	private int value;
	private boolean empty = true;

	public synchronized int fetch() {
		while (empty) {
			try {
				wait();
			} catch (InterruptedException e) {
			}
		}
		empty = true;
		notify();
		return value;
	}

	public synchronized void store(int value) {
		while (!empty) {
			try {
				wait();
			} catch (InterruptedException e) {
			}
		}
		this.value = value;
		empty = false;
		notify();
	}
}